<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <script src="/layui/layui.js" charset="utf-8"></script>
</head>

<body>
<div class="layui-container">
    <div class="layui-row">
        <div class="layui-col-lg-offset3" layui-col-lg6>
            <div class="layui-form layuimini-form">
                <form class="layui-form" action="" lay-filter="userForm">
                    <div class="layui-form-item">
                        <label class="layui-form-label">医生姓名：</label>
                        <div class="layui-input-block">
                            <input type="text" name="drealname" required lay-verify="required" placeholder="请输入用户名"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <input type="hidden" name="id" value="" class="layui-input">



                    <div class="layui-form-item">
                        <label class="layui-form-label">性别：</label>
                        <div class="layui-input-block">
                            <input type="radio" name="sex" value="男" title="男">
                            <input type="radio" name="sex" value="女" title="女" checked>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">科室：</label>
                        <div class="layui-input-block">
                            <select id="ks" name="ks" lay-filter="ks">
                                <option value="0">请选择科室</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">职位：</label>
                        <div class="layui-input-block">
                            <select id="zw" name="zw" lay-filter="zw">
                                <option value="0">请选择职位</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">学历：</label>
                        <div class="layui-input-block">
                            <select id="xl" name="xl" lay-filter="xl">
                                <option value="0">请选择学历</option>
                            </select>
                        </div>
                    </div>

                    <div class="layui-form-item layui-form-text">
                        <label class="layui-form-label">专业：</label>
                        <div class="layui-input-block">
                            <select id="zy" name="zy" lay-filter="zy">
                                <option value="0">请选择专业</option>
                            </select>
                        </div>
                    </div>



        <div class="layui-form-item">
        <label class="layui-form-label">联系方式：</label>
    <div class="layui-input-block">
        <input type="text" name="dphone" required lay-verify="required" placeholder="请输入电话号码"
    autocomplete="off" class="layui-input">
        </div>

        </div>

        <div class="layui-form-item">
        <label class="layui-form-label">邮箱：</label>
    <div class="layui-input-block">
        <input type="email" name="demail" required lay-verify="required" placeholder="请输入邮箱"
    autocomplete="off" class="layui-input">
        </div>

        </div>

        <div class="layui-form-item">
        <label class="layui-form-label">头像：</label>
    <div class="layui-input-block">
        <!--                            <input type="file" name="durl" required lay-verify="required" placeholder=""-->
        <!--                                   autocomplete="off" class="layui-input">-->

        <button type="button" class="layui-btn" id="durl">
        <i class="layui-icon">&#xe67c;</i>上传图片
    </button>

    </div>

    </div>



    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">医生描述：</label>
    <div class="layui-input-block">
        <textarea name="dtext" placeholder="请输入描述信息" class="layui-textarea"></textarea>
        </div>
        </div>


        <div class="layui-form-item">
        <div class="layui-input-block">
        <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
        </div>
        </form>
        </div>

        </div>
        </div>
        </div>



        <script>
        //Demo
        layui.use(['form','element','upload'], function () {
        var form = layui.form
            , $ = layui.jquery
            ,element = layui.element
            ,upload = layui.upload
            , laydate = layui.laydate;




        //日期   渲染上面 id 为 date 的 标签
        laydate.render({
            elem: '#date'
        });

        //执行实例
        var uploadInst = upload.render({
            elem: '#durl' //绑定元素
            ,url: '/upload/' //上传接口
            ,done: function(res){
                //上传完毕回调
            }
            ,error: function(){
                //请求异常回调
            }
        });


        $(function (){
            // 查询科室列表  动态渲染下拉列表
            $.ajax({
                url:"/htype?method=doctorTypeList",
                success:function (result){
                    for(var i=0;i<result.data.length;i++){
                        if(result.data[i].tgroup==2){
                            //科室
                            var option = "<option value=\""+result.data[i].tid+"\"> "+result.data[i].tname+"</option>";
                            //alert(option);
                            $("#ks").append(option);
                        }

                        if(result.data[i].tgroup==4){
                            //学历
                            var option = "<option value=\""+result.data[i].tid+"\"> "+result.data[i].tname+"</option>";
                            //alert(option);
                            $("#xl").append(option);
                        }

                        if(result.data[i].tgroup==3){
                            //职位
                            var option = "<option value=\""+result.data[i].tid+"\"> "+result.data[i].tname+"</option>";
                            //alert(option);
                            $("#zw").append(option);
                        }
                        if(result.data[i].tgroup==5){
                            //专业
                            var option = "<option value=\""+result.data[i].tid+"\"> "+result.data[i].tname+"</option>";
                            //alert(option);
                            $("#zy").append(option);
                        }

                    }

                    form.render('select','userForm');  // 重新渲染 下拉列表  必须有 要不然数据不显示
                },
                dataType: "json"
            });

        });

        // 从 localStorage 把数据取出来   并转成 js 对象
        //  JSON.parse("str")   把字符串转为 js 对象
        //var data = JSON.parse(localStorage.getItem("user"));

        //给表单数据赋值
        // form.val("userForm",{
        //      "drealname":"xxxx",
        //     // "sex":data.sex,
        //     // "id":data.id,
        //     // "birthday":data.birthday,
        //     // "phone":data.phone,
        //     // "address":data.address,
        //     //"ks":"<option>皮肤科</option>"
        // });

        // token 前后端分离再用
       // var token = JSON.parse(localStorage.getItem("token"));

        //监听提交
        form.on('submit(formDemo)', function (data) {
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                "url":"http://localhost:8080/addStudent",
               // "headers":{"token":token},
                "data": data.field,
                // result 参数 表式后台响应的数据
                "success":function(result){
                    if(result.code == 0){

                        // 关闭 弹出层
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.layer.msg("添加成功");
                        parent.layer.close(iframeIndex);

                    }else{
                        layer.msg(result.msg);
                    }
                },
                "dataType":"json"
            });

            return false;
        });
    });
</script>


</body>

</html>